import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { STColumn, STComponent, STPage, STChange } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { GridComponent, PopdetailComponent, HttpService, SupDic } from 'lbf';
import { ActivatedRoute } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { ReuseTabService } from '@delon/abc/reuse-tab';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { SVModule } from '@delon/abc';

@Component({
  selector: 'app-ybzh-ylbxsh',
  templateUrl: './ylbxsh.component.html',
})
export class YbzhYlbxshComponent implements OnInit {
  dataset = [];
  isVisible = false;
  chVisible = false;
  formData = {};
  PROJID = '1';
  DAD069 = '';
  AAC001: any = {};

  detall_data: any = { AAE070: '', AKC038: '' };
  params = { sname: 'BJXX_QUERY', queryparas: {} };
  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '受理', value: '1' },
          { label: '不受理', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          // asyncData: () => of().pipe(delay(100)),
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '受理建议',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 80,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
  };

  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
  ) {
    this.reuseTabService.title = '医疗报销审核';
  }

  sdSchema: SFSchema = {
    properties: {
      AAE070: {
        type: 'string',
        title: '结算日期',
        readOnly: true,
        ui: {
          widget: 'date',
          grid: { span: 6 },
        },
      },
      AKC038: {
        type: 'string',
        title: '门诊住院号',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AAC001: {
        type: 'string',
        title: '个人编号',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AAC002: {
        type: 'string',
        title: '身份证',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AAC003: {
        type: 'string',
        title: '姓名',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AAC004: {
        type: 'string',
        title: '性别',
        enum: this.supDic.getSFDic('AAC004'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AAC008: {
        type: 'string',
        title: '人员状态',
        enum: this.supDic.getSFDic('AAC008'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AAE140: {
        type: 'string',
        title: '险种',
        enum: this.supDic.getSFDic('AAE140'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      YKB003: {
        type: 'string',
        title: '参保地机构代码',
        enum: this.supDic.getSFDic('YKB003'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC801: {
        type: 'string',
        title: '就医地机构代码',
        enum: this.supDic.getSFDic('AKC801'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC020: {
        type: 'string',
        title: '医疗保险卡号',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC100: {
        type: 'string',
        title: '医保人员类别',
        enum: this.supDic.getSFDic('AKC100'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      CKC013: {
        type: 'string',
        title: '交易类型',
        enum: this.supDic.getSFDic('AKC100'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC001: {
        type: 'string',
        title: '就诊类别',
        enum: this.supDic.getSFDic('AKC001'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC046: {
        type: 'string',
        title: '医疗费总额',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AKC258: {
        type: 'string',
        title: '自理费用',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC259: {
        type: 'string',
        title: '自费费用',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC277: {
        type: 'string',
        title: '自负费用',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKB001: {
        type: 'string',
        title: '医院编号',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      YYMC: {
        type: 'string',
        title: '医院名称',
        readOnly: true,

        ui: { grid: { span: 6 } },
      },
      AKB002: {
        type: 'string',
        title: '实际医院名称',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AKA001: {
        type: 'string',
        title: '医院等级',
        enum: this.supDic.getSFDic('AKA001'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKA002: {
        type: 'string',
        title: '医疗机构类别',
        enum: this.supDic.getSFDic('AKA002'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AAB001: {
        type: 'string',
        title: '单位编号',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AAB004: {
        type: 'string',
        title: '单位名称',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AAB019: {
        type: 'string',
        title: '单位类型',
        enum: this.supDic.getSFDic('AAB019'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKE045: {
        type: 'string',
        title: '病种类型',
        enum: this.supDic.getSFDic('AKE045'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKE042: {
        type: 'string',
        title: '疾病编码',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      JBMC: {
        type: 'string',
        title: '疾病名称',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC327: {
        type: 'string',
        title: '可报医疗费',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC260: {
        type: 'string',
        title: '起付标准金额',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC274: {
        type: 'string',
        title: '个人帐户金额',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC275: {
        type: 'string',
        title: '本年帐户金额',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC261: {
        type: 'string',
        title: '统筹支付',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC262: {
        type: 'string',
        title: '高额补充',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC263: {
        type: 'string',
        title: '公务员补助',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC264: {
        type: 'string',
        title: '记帐金额',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKC276: {
        type: 'string',
        title: '现金支付',
        readOnly: true,
        ui: {
          grid: { span: 6 },
        },
      },
      AKA042: {
        type: 'string',
        title: '入院类型',
        enum: this.supDic.getSFDic('AKA042'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC041: {
        type: 'string',
        title: '入院日期',
        readOnly: true,
        ui: {
          widget: 'date',
          grid: { span: 6 },
        },
      },
      AKC043: {
        type: 'string',
        title: '出院日期',
        readOnly: true,
        ui: {
          widget: 'date',
          grid: { span: 6 },
        },
      },
      AKC044: {
        type: 'string',
        title: '出院原因',
        enum: this.supDic.getSFDic('AKC044'),
        readOnly: true,
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      CKC907: {
        type: 'string',
        title: '天数',
        readOnly: true,
        ui: { grid: { span: 6 } },
      },
      AKA130: {
        type: 'string',
        title: '医疗类别',
        readOnly: true,
        enum: this.supDic.getSFDic('AKA130'),
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKB099: {
        type: 'string',
        title: '结算类型',
        readOnly: true,
        enum: this.supDic.getSFDic('AKB099'),
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      AKC078: {
        type: 'string',
        title: '主要病情诊断',
        readOnly: true,
        ui: {

          grid: { span: 6 },
        },
      },
      CKC009: {
        type: 'string',
        title: '交易流水号',
        ui: {
          hidden: true,
          grid: { span: 6 },
        },
      },
    },
    ui: {
      spanLabelFixed: 130,
      grid: { span: 7 },
    },
  };


  flag = false;

  tabMode = 'bjxx';
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('st', { static: false }) st: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;



  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    { title: '材料数量', index: 'STUFFNUM', width: '25%' },
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },
  ];
  page: STPage = {
    show: false,
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.BXSH_QUERY();
      this.YBCL_QUERY();
    }
  }

  //打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.BXSH_QUERY();
      this.YBCL_QUERY();
    }
  }

  //事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }
  //界面赋值
  BXSH_QUERY() {
    this.lbservice
      .lbservice('BXSH_QUERY', { para: { DAD069: this.DAD069 } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf.formData = resdata.message.list[0];
          this.detall_data = resdata.message.list[0];
          //this.flag = true;
          this.sf.reset();
        }
      });
  }
  //材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCL_QUERY', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }
  //受理保存
  lc_insert() {
    this.lbservice
      .lbservice('bxsh_insert', {
        para: {
          PROJID: this.PROJID,
          DAD069: this.DAD069,
          sf: this.sf.value,
          slxx: this.slxx.value,
        },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          if (this.slxx.getValue('/DAD095') === '0') {
            this.msgSrv.info('操作成功');
          } else {
            this.msgSrv.info('保存成功');
          }
          this.sf.formData = null;
          this.sf.reset();
        }
      });
  }

  // tslint:disable-next-line:all
  pname = '审核信息';
  // tslint:disable-next-line: member-ordering
  active = true;
  // tslint:disable-next-line: member-ordering
  icon1 = 'caret-right';
  // tslint:disable-next-line: member-ordering
}
